package com.hbnu.mysql;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DatabaseDemo11 {
    //使用封装好的工具类实现模糊查询

    public static void main(String[] args) {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;

        try {
            //获取连接
            connection = DBUtils.getConnection();
            String sql = "select * from nncc1 where c1 like ?";

            preparedStatement = connection.prepareStatement(sql);

            preparedStatement.setString(1,"%");       //百分号表示通配符
            resultSet = preparedStatement.executeQuery();

            while (resultSet.next()){
                String c1 = resultSet.getString("c1");
                System.out.println(c1);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
        finally {
            DBUtils.close(resultSet,preparedStatement,connection);
        }
    }
}
